package com.liuww.webserver;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Properties;

public class WebServer {

	public static void serverStart(int port){
		try {
			ServerSocket serverSocket = new ServerSocket(port);
			while(true){
				Socket socket = serverSocket.accept();
				new Processor(socket).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	public static void main(String[] args) {

		Properties properties = new Properties();
		try {
			String filePath = ClassLoader.getSystemResource("").getPath() + "com/liuww/webserver/server.properties";
			InputStream in = new FileInputStream(filePath);
			properties.load(in);
			String port = properties.getProperty("port");
			serverStart(Integer.parseInt(port));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	

}
